var register;
$(function () {
    register = new Vue({
        el:'#registerController',
        data:{
            account:{
                phone:'',
                code:'',
                pwd:'',
                repeatPwd:''
            },
            codeEnable:true,
            codeValue:'获取验证码'
        },
        methods:{
            regist:function () {
                var that = this;
                var account = that.account;
                if (!account.phone){
                    sy.msg('请输入手机号!');
                    return;
                }
                if (!sy.isPhone(account.phone)){
                    sy.msg('请输入正确的手机号!');
                    return;
                }
                if (!account.code){
                    sy.msg('请输入验证码!');
                    return;
                }
                if (!account.pwd){
                    sy.msg('请输入密码!');
                    return;
                }
                if (!account.repeatPwd){
                    sy.msg('请再次输入密码!');
                    return;
                }
                if (account.pwd != account.repeatPwd){
                    sy.msg('两次密码不一致!');
                    return;
                }
                sy.post('/web/login/register',{
                    phone:account.phone,
                    code:account.code,
                    pwd:hex_md5(account.pwd)
                },function (data) {
                    if (data.code == 0){
                        location.href = sy.path+'/web/login';
                    }
                })
            },
            getCode:function () {
                var that = this;
                if (that.codeEnable){
                    sy.postApi('/api/account/getMobileMsg',{
                        phone:that.account.phone,
                        type:1
                    },function (data) {

                    })
                    //请求
                    that.calCodeTime();
                }
            },
            calCodeTime:function () {//计算倒计时
                var that = this;
                if(waits==0){
                    that.codeEnable = true;
                    that.codeValue = '获取验证码'
                }else{
                    that.codeEnable = false;
                    that.codeValue = waits+" s";
                    waits--;
                    setTimeout(function(){
                        that.calCodeTime();
                    },1000)
                }
            }
        }
    });
})